/**
 * 退单管理管理初始化
 */
var RefundOrder = {
    id: "RefundOrderTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
RefundOrder.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '退单号', field: 'refundNo', visible: true, align: 'center', valign: 'middle'},
        {title: '订单号', field: 'orderNo', visible: true, align: 'center', valign: 'middle'},
        {title: '创建人', field: 'nickName', visible: true, align: 'center', valign: 'middle'},
        {title: '发车时间', field: 'depTime', visible: true, align: 'center', valign: 'middle'},
        {title: '乘车人', field: 'passenger', visible: true, align: 'center', valign: 'middle'},
        {title: '座位号', field: 'seatNo', visible: true, align: 'center', valign: 'middle'},
        {title: '座位类型', field: 'seatType', visible: true, align: 'center', valign: 'middle'},
        {title: '车票id', field: 'ticketId', visible: false, align: 'center', valign: 'middle'},
        {title: '原票价', field: 'oldPrice', visible: true, align: 'center', valign: 'middle'},
        {title: '退款比例(%)', field: 'refundRadio', visible: true, align: 'center', valign: 'middle'},
        {title: '退款金额', field: 'refundPrice', visible: true, align: 'center', valign: 'middle'},
        {title: '退款状态', field: 'status', visible: true, align: 'center', valign: 'middle'},
        {title: '申请时间', field: 'applyTime', visible: true, align: 'center', valign: 'middle'},
        {title: '退款时间', field: 'auditTime', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
RefundOrder.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        RefundOrder.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加退单管理
 */
RefundOrder.openAddRefundOrder = function () {
    var index = layer.open({
        type: 2,
        title: '添加退单管理',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/refundOrder/refundOrder_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看退单管理详情
 */
RefundOrder.openRefundOrderDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '退单管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/refundOrder/refundOrder_update/' + RefundOrder.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除退单管理
 */
RefundOrder.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/refundOrder/delete", function (data) {
            Feng.success("删除成功!");
            RefundOrder.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("refundOrderId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询退单管理列表
 */
RefundOrder.search = function () {
    var queryData = {};
    queryData['refundNo'] = $("#refundNo").val();
    queryData['orderNo'] = $("#orderNo").val();
    queryData['openid'] = $("#openid").val();
    RefundOrder.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = RefundOrder.initColumn();
    var table = new BSTable(RefundOrder.id, "/refundOrder/list", defaultColunms);
    table.setPaginationType("client");
    RefundOrder.table = table.init();
});
